﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using control.Biz;

namespace control
{
    public partial class QLPhieuNhap : Form
    {
        List<BizPhieuNhap> phieunhaps = new List<BizPhieuNhap>();
        public QLPhieuNhap()
        {
            InitializeComponent();
        }

        private void QLPhieuNhap_Load(object sender, EventArgs e)
        {
            phieunhaps = BizPhieuNhap.GetAll();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = phieunhaps;
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frmPhieuNhap frm = new frmPhieuNhap();
            frm.ShowDialog();
            phieunhaps = BizPhieuNhap.GetAll();
            binding();
        }

        private void binding()
        {
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = phieunhaps;
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ban co muon xoa khong ?", "Xac Dinh", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                {
                    phieunhaps[row.Index].Delete();
                }
                phieunhaps = BizPhieuNhap.GetAll();
                binding();
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {

            if (phieunhaps.Count != 0)
            {
                BizPhieuNhap pn = phieunhaps[dataGridView1.SelectedRows[0].Index];
                frmPhieuNhap frm = new frmPhieuNhap(pn);
                frm.ShowDialog();
                phieunhaps = BizPhieuNhap.GetAll();
                binding();
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            phieunhaps = BizPhieuNhap.Find(textBox1.Text, dateTimePicker1.Value, dateTimePicker2.Value);
            binding();
        }
    }
}
